package com.source.boot01.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author wengqy
 * @Date 2021/1/22
 */
@Controller
public class RequestController {

    // http://localhost:8080/goto
    @GetMapping("/goto")
    public  String  goTopage(HttpServletRequest request){
        request.setAttribute("msg","成功了");
        request.setAttribute("code",200);
        return "forward:/success";
    }

    @ResponseBody
    @GetMapping("/success")
    public  Map<String, Object>  goTopage(@RequestAttribute("msg")String msg,
                                          @RequestAttribute("code")String code,
                                          HttpServletRequest request){
        Object msgg = request.getAttribute("msg");
        Object  codee = request.getAttribute("code");
        Map<String,Object>   map  = new HashMap();
        map.put("msgg",msgg );
        map.put("codee",codee );
        map.put("annotayion_msg",msg );
        map.put("annotayion_code",code );

        return map; // {"msgg":"成功了","annotayion_msg":"成功了","annotayion_code":"200","codee":200}
    }


}
